﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using jSLApp.Client.Forms;
using jSLApp.Client.MainService;
using jSLCore.Client.Presentation.BaseControl;
using jSLCore.Client.Presentation.BaseControl.Selection;
using jSLCore.Client.Utility;

namespace jSLApp.Client.Controls
{
    public partial class MessageGrid : jSLGrid
    {
        public MessageGrid()
        {
            InitializeComponent();
            Style = (Style)Resources["selGrid"];
            HightlightNew = true;
        }

        public bool HightlightNew { get; set; }

        private void row_Loading(object sender, DataGridRowEventArgs e)
        {
            if (HightlightNew)
            {
                var message = (Message) e.Row.DataContext;
                if (!message.IsReaded) e.Row.Background = new SolidColorBrush(Colors.Yellow);
            }
        }

        public bool ShowFrom
        {
            get { return fromColumn.Visibility == Visibility.Visible; }
            set
            {
                fromColumn.Visibility = value?Visibility.Visible : Visibility.Collapsed;
            }
        }

        public bool ShowTo
        {
            get { return toColumn.Visibility == Visibility.Visible; }
            set
            {
                toColumn.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
            }
        }

        private void goto_Details(object sender, RowSelectedEventArgs e)
        {
            var message = (Message) e.RowObject;
            var dlg = new MessageDetail(message.id);
            dlg.ShowDialog(this.FindAncestor<BaseControl>());
        }
    }
}
